using System;
using System.Collections.Generic;
using System.Text;

using System.Windows.Forms;

using GURUCORE.Lib.Core;
using GURUCORE.Framework.Core;

namespace GURUCORE.GForm.Core
{
    /// <summary>
    /// write all WinForm relate util function here
    /// Do not write 3rd relate function, for example, infagisristic, c1, ...
    /// </summary>
    public static class Util
    {
        public static void ThisIsUtilFunction()
        {
        }

        
        /// <summary>
        /// this method to check data in control if they are empty
        /// </summary>
        /// <param name="pobjControl">TextBox, ComboBox</param>
        /// <returns>true if control has value or control does not need to have value</returns>
        public static bool CheckValidate(System.Windows.Forms.Control p_Control, bool p_bIsRequire)
        {
            if (!p_bIsRequire)
            {
                return true;
            }


            if (p_Control is TextBoxBase)
            {
                if (ConvertSafe.ToString((p_Control as TextBoxBase).Text).Trim() == string.Empty)
                {
                    return false;
                }
            }
            else if (p_Control is ComboBox)
            {
                if(ConvertSafe.ToString((p_Control as ComboBox).Text).Trim() == string.Empty)
                {
                    return false;
                }
            }
            
            return true;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="p_Control"></param>
        /// <returns>true if control has value or control does not need to have value</returns>
        public static bool CheckValidate(System.Windows.Forms.Control p_Control)
        {
            return CheckValidate(p_Control, true);
        }


        /////    <Description>
        /////       check numberic
        /////    </Description>        
        //public static bool CheckValidateNumeric(Control p_Control)
        //{


        
        //    if (!FormControlComponents.IsNumeric(txtTextBox.Text))
        //    {
        //        return false;
        //    }
        //    return true;
        //}




        //public static bool IsNumeric(string pstrNumber)
        //{
        //    try
        //    {
        //        double dblResult = 0;
        //        return Double.TryParse(pstrNumber, System.Globalization.NumberStyles.Any,
        //            System.Globalization.NumberFormatInfo.CurrentInfo, out dblResult);
        //    }
        //    catch
        //    {
        //        return false;
        //    }
        //}

        
        ///// <summary>             
        ///// </summary>
        ///// <param name="pstrNumber"></param>
        ///// <returns></returns>
        //public static bool IsPositiveNumeric(string pstrNumber)
        //{
        //    try
        //    {
        //        decimal decResult = 0;
        //        decResult = decimal.TryParse(pstrNumber, );
        //        if (decResult <= 0)
        //        {
        //            return false;
        //        }
        //        else
        //        {
        //            return true;
        //        }
        //    }
        //    catch
        //    {
        //        return false;
        //    }
        //}

        ///// <summary>
        ///// Validate percent number between 0 and 100
        ///// </summary>
        ///// <param name="pstrNumber">Number of percent to be validated</param>
        ///// <returns>boolean</returns>
        //public static bool IsValidPercent(string pstrNumber)
        //{
        //    try
        //    {
        //        if (IsPositiveNumeric(pstrNumber))
        //        {
        //            double dblNumber = 0;
        //            if (Double.TryParse(pstrNumber, System.Globalization.NumberStyles.Any,
        //                                System.Globalization.NumberFormatInfo.CurrentInfo, out dblNumber))
        //            {
        //                if ((dblNumber > 0) && (dblNumber <= 100))
        //                {
        //                    return true;
        //                }
        //                else
        //                {
        //                    return false;
        //                }
        //            }
        //            else
        //            {
        //                return false;
        //            }
        //        }
        //        else
        //        {
        //            return false;
        //        }
        //    }
        //    catch
        //    {
        //        return false;
        //    }
        //}

    }
}
